<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:p="http://primefaces.prime.com.tr/ui"> 

<h:head>
<script type="text/javascript">
	function handleComplete(xhr, status, args){ 
		if(typeof(args.success) == "undefined"){
			return false;
			}
		else if(args.success){
			addNewCompanyDialog.hide()
			//document.getElementById('adminForm:btnRefresh').click();
			}
		}

	function resetForm(){
		var fields = document.getElementById('adminForm:dialogAdd').getElementsByTagName('input');
		alert(fields);
		for(var i=fields.length-1;i>=0; i--){
			clearField(fields[i]);
			}
		}
	
	function clearField(field){
		field.value = '';
		}
</script>
	 <link type="text/css" rel="stylesheet" href="../css/redmond/skin.css"/> 
<h:outputScript name="jsf.js" library="javax.faces"/> 
</h:head> 
<body style="font-family: Verdana, Arial, sans-serif;
font-size: 12px;">
<h:form id="adminForm" prependId="false">
	<p:panel>
	<p:messages globalOnly="true" id="msgGlobal"/>
	<p:commandButton value="添加一个新客户" process="@this" update="dialogAdd msgGlobal" oncomplete="addNewCompanyDialog.show();" style="font-weight:bold;"></p:commandButton>
	<br/>
		<p:dataTable value="#{superAdminBean.companies}" var="c" id="companyTbl">
			<p:column>
				<f:facet name="header">
					<h:outputText value="id"></h:outputText>
				</f:facet>
				<h:outputText value="#{c.id}" />
			</p:column>
			<p:column >
				<f:facet name="header">
				<h:outputText value="公司"></h:outputText>
				</f:facet>
				<h:outputText value="#{c.companyName}" />
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="城市"></h:outputText>
				</f:facet>
				<h:outputText value="#{c.city}" />
			</p:column>
			<p:column>
				<f:facet name="header">
				<h:outputText value="地址"></h:outputText>
				</f:facet>
				<h:outputText value="#{c.address}" />
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="剩余条数"></h:outputText>
				</f:facet>
				<h:outputText value="#{c.contract.number - c.contract.numberBeenUsed}" />
			</p:column>
			<p:column>
				<p:commandLink process="@this" value="编辑">
					<f:setPropertyActionListener target="#{superAdminBean.selectedCompany}" value="#{c}"></f:setPropertyActionListener>
				</p:commandLink>
			</p:column>
			<p:column>
				<p:commandLink process="@this" value="删除" update="pnDelete" oncomplete="deleteConfirmDialog.show()">
					<f:setPropertyActionListener target="#{superAdminBean.selectedCompany}" value="#{c}"></f:setPropertyActionListener>
				</p:commandLink>
			</p:column>
		</p:dataTable>
	</p:panel>
	<p:dialog  header="添加新客户" modal="true" widgetVar="addNewCompanyDialog" width="400" id="dialogAdd"  >
	<p:messages id="msgAdd"></p:messages>
		<h:panelGrid columns="2" id="pnCreate">
			<h:outputText value="公司名称"/>
			<h:inputText value="#{superAdminBean.newCompanyName}" required="true" requiredMessage="请输入公司名称"/>
			<h:outputText value="城市"/>
			<h:inputText value="#{superAdminBean.city}" required="true" requiredMessage="请输入公司所在城市"/>
			<h:outputText value="公司地址"/>
			<h:inputText value="#{superAdminBean.address}"/>
			<h:outputText value="联系人"/>
			<h:inputText value="#{superAdminBean.adminName}"/>
			<h:outputText value="电话"/>
			<h:inputText value="#{superAdminBean.adminPhone}" required="true" requiredMessage="请输入联系人电话"/>
			<h:outputText value="联系人Email"/>
			<h:inputText value="#{superAdminBean.adminEmail}"/>
			<h:outputText value="登陆用户名"/>
			<h:inputText value="#{superAdminBean.login}" required="true" requiredMessage="请输入用户登陆用户名"/>
			<h:outputText value="购买条数"/>
			<h:inputText value="#{superAdminBean.number}" required="true">
			</h:inputText>
			<h:outputText value="企业代码"/>
			<h:inputText value="#{superAdminBean.x_eid}" required="true" requiredMessage="请输入企业代码">
			</h:inputText>
			<h:outputText value="企业用户名"/>
			<h:inputText value="#{superAdminBean.x_uid}" required="true" requiredMessage="请输入企业用户名">
			</h:inputText>
			<h:outputText value="企业密码"/>
			<h:inputText value="#{superAdminBean.x_pwd}" required="true" requiredMessage="请输入企业密码">
			</h:inputText>
			<p:commandButton value="添加"  actionListener="#{superAdminBean.addNewCompany}" process="dialogAdd" oncomplete="handleComplete(xhr, status, args)" update="msgAdd companyTbl msgGlobal"></p:commandButton>
				<p:commandButton oncomplete="resetForm()" process="@this"/>
		
		</h:panelGrid>
	</p:dialog>
	<p:dialog modal="true" widgetVar="deleteConfirmDialog" id="dialogConfirmDel">
	<h:panelGrid id="pnDelete">
		<h:outputText value="确定要删除该客户么？"></h:outputText>
		<h:outputText value="#{superAdminBean.selectedCompany.companyName}" id="toDelCompanyName" style="font-weight:bold;"></h:outputText>
		<h:panelGrid columns="2">
			<p:commandButton value="删除" actionListener="#{superAdminBean.deleteCompany}" process="@this" update="companyTbl msgGlobal" oncomplete="deleteConfirmDialog.hide()"/>
			<p:commandButton value="取消" onclick="deleteConfirmDialog.hide()" />
	
		</h:panelGrid>
		</h:panelGrid>
	</p:dialog>
	<p:dialog >
		<p:panel header="账号管理">
			<h:panelGrid>
				
			</h:panelGrid>
		</p:panel>
	</p:dialog>
</h:form> 

</body> 
</html>
